#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

// 求总重量不超过c的装载最大数量
int maxLoading(vector<int>& w, int c) {
    // 对物品重量数组进行排序
    sort(w.begin(), w.end());
    int n = 0, l = 0;

    // 贪心选择：当前最轻的物品如果能装得下，则装上货车
    while (n < w.size() && l + w[n] <= c) {
        l += w[n];
        n++;
    }

    return n;
}

int main() {
    vector<int> w = {10, 30, 20, 40, 10};
    int c = 70;
    int n = maxLoading(w, c);
    cout << "最大装载数量为: " << n << endl;
    return 0;
}